<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>提现</title>
    <!-- 引入 WeUI CDN 链接 -->
    <link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/2.3.0/weui.min.css"/>
    <link rel="stylesheet" href="./css/base.css"/>

</head>
<body>
<div class="page">
    <div style="height: 50px;line-height: 50px;background-color: #f7f7f7;">
        <a href="/user" ><img src="./img/back.png"  style="vertical-align:middle;width: 20px">
            <span style="color: #000;vertical-align:middle;font-weight: bold">返回</span>
        </a>
    </div>

    <div class="weui-form" style="min-height:80%">
        <div class="weui-form__text-area">
            <h2 class="weui-form__title">佣金提现</h2>
            <div class="weui-form__desc">可提现金额: <span id="s-commission">{{$user['commission']}}</span></div>
        </div>
        <div class="weui-form__control-area">
            <div class="weui-cells__group weui-cells__group_form">

                <div class="weui-cells weui-cells_form">
                    <div class="weui-cell weui-cell_active">
                        <div class="weui-cell__hd"><label class="weui-label">提现金额</label></div>
                        <div class="weui-cell__bd">
                            <input  class="weui-input" id="i-amount"  placeholder="请输入提现金额"/>
                        </div>
                    </div>
                </div>
                <div class="weui-cells weui-cells_form">
                    <div class="weui-cell weui-cell_active">
                        <div class="weui-cell__hd"><label class="weui-label">提现至</label></div>
                        <div class="weui-cell__bd">
                            <div style="float: right">
                                <img src="./img/zfb.jpg" style="vertical-align: middle;width: 20px" alt="">
                                <span style="vertical-align: middle;color: #666;font-size: 13px">支付宝账户</span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="weui-cells weui-cells_form">
                    <div class="weui-cell weui-cell_active">
                        <div class="weui-cell__hd"><label class="weui-label">姓名</label></div>
                        <div class="weui-cell__bd">
                            <input  class="weui-input" id="i-real"  placeholder="支付宝真实姓名" value="{{$real_name}}"/>
                        </div>
                    </div>
                </div>
                <div class="weui-cells weui-cells_form">
                    <div class="weui-cell weui-cell_active">
                        <div class="weui-cell__hd"><label class="weui-label">账号</label></div>
                        <div class="weui-cell__bd">
                            <input  class="weui-input" id="i-zfb" placeholder="支付宝账号" value="{{$zfb_account}}"/>
                        </div>
                    </div>
                </div>
            </div>
            <p style="font-size: 13px;color: #666;margin: 3% 0 0 8%">提现金额需为10的倍数，单次不能超过5000</p>
        </div>

        <div class="weui-form__opr-area">
            <a class="weui-btn weui-btn_primary" id="doWithdraw" href="javascript:" >确定</a>
        </div>
    </div>
    <div class="weui-toptips weui-toptips_warn" id="topTips"></div>

</div>
<script src="./js/zepto.min.js"></script>

<script type="text/javascript">


    $("#doWithdraw").click(function(){
        const amount = $("#i-amount").val();
        const real = $("#i-real").val();
        const zfb = $("#i-zfb").val();
        if(amount <= 0 || amount % 10 !== 0){
            msg('提现金额需大于0且为10的倍数');
            return false
        }
        if(parseFloat(amount) > parseFloat($("#s-commission").text())){
            msg('提现金额超过佣金总金额');
            return false
        }
        if(!real || !zfb) {
            msg('真实姓名和支付宝账号不能为空');
            return false
        }
        $.post('/withdraw', {amount: amount, real_name : real, zfb_account: zfb}, function (res) {
            if (res.code !== 0) {
                msg(res.msg);
            } else {
                msg("提现成功");
                setTimeout(function () {
                    window.location.href = '/user'
                }, 1500)
            }
        })

        function msg(msg, time = 1000) {
            const topTip = $('#topTips');
            topTip.text(msg);
            topTip.fadeIn(msg);
            setTimeout(function () {
                topTip.fadeOut()
            }, time)
        }
    })

</script>
</body>
</html>